package com.dkts.oil.util;

public class SystemEnvUtil {
    private SystemEnvUtil() {
    }

    public static byte[] copyAndPadArray(byte[] source, int targetLength) {
        byte[] target = new byte[targetLength];
        int length = Math.min(source.length, targetLength);
        System.arraycopy(source, 0, target, 0, length);
        for (int i = length; i < targetLength; i++) {
            target[i] = 0;
        }
        return target;
    }

    public static int getJDKVersion(String javaVersionStr) {
        int version = 0;
        char[] var2 = javaVersionStr.toCharArray();
        int var3 = var2.length;

        for (int var4 = 0; var4 < var3; ++var4) {
            char ch = var2[var4];
            if (Character.isDigit(ch)) {
                version = version * 10 + (ch - 48);
            } else {
                if (version != 1) {
                    break;
                }

                version = 0;
            }
        }

        return version;
    }

    private static boolean isJDK_N_OrHigher(int n) {
        String javaVersionStr = System.getProperty("java.version", "");
        if (javaVersionStr.isEmpty()) {
            return false;
        } else {
            int version = getJDKVersion(javaVersionStr);
            return version > 0 && n <= version;
        }
    }

    public static boolean isJDK5() {
        return isJDK_N_OrHigher(5);
    }

    public static boolean isJDK6OrHigher() {
        return isJDK_N_OrHigher(6);
    }

    public static boolean isJDK7OrHigher() {
        return isJDK_N_OrHigher(7);
    }

    public static boolean isJDK16OrHigher() {
        return isJDK_N_OrHigher(16);
    }

    public static boolean isJDK18OrHigher() {
        return isJDK_N_OrHigher(18);
    }

    public static boolean isJDK21OrHigher() {
        return isJDK_N_OrHigher(21);
    }

    public static boolean isWindows() {
        String os = System.getProperty("os.name");
        return os.startsWith("Windows");
    }
}
